﻿
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>ECharts</title>
    <!-- 引入 echarts.js -->
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery.min1.3.5.js"></script>
    <script src="${pageContext.request.contextPath}/js/echarts.min.js"></script>
    <script src="${pageContext.request.contextPath}/js/china.js"></script>
    <script type="text/javascript" src="https://cdn-hangzhou.goeasy.io/goeasy.js"></script>
</head>
<body>
<!-- 为ECharts准备一个具备大小（宽高）的Dom -->
<div id="main" style="width: 600px;height:400px;"></div>
<div id="line" style="width: 600px;height:400px;"></div>
<div id="china" style="width: 600px;height:400px;"></div>
<div id="hello" style="width: 600px;height:400px;"></div>
<script type="text/javascript">
    // 基于准备好的dom，初始化echarts实例
    var myChart = echarts.init(document.getElementById('main'));

    // 指定图表的配置项和数据
    var option = {
        title: {
            text: '用户男女比例图'
        },
        tooltip: {},
        legend: {
            data:['人数']
        },
        xAxis: {
            data: ["男","女"]
        },
        yAxis: {},
    };


    // 基于准备好的dom，初始化echarts实例
    var myLine = echarts.init(document.getElementById('line'));

    // 指定图表的配置项和数据
    var option1 = {
        title: {
            text: '用每周户注册量'
        },
        tooltip: {},
        legend: {
            data:['人数']
        },
        xAxis: {
            data: ["第一周","第二周","第三周"]
        },
        yAxis: {},
    };

    // 2.通过init方法初始化图表
    var myChina = echarts.init(document.getElementById('china'));

    var option2 = {
        title : {
            text: '用户地区分布',
            left: 'center'
        },
        tooltip : {
            trigger: 'item'
        },
        legend: {
            orient: 'vertical',
            left: 'left',
            data:['用户人数']
        },
        visualMap: {
            min: 0,
            max: 2500,
            left: 'left',
            top: 'bottom',
            text:['高','低'],           // 文本，默认为数值文本
            calculable : true
        },
        toolbox: {
            show: true,
            orient : 'vertical',
            left: 'right',
            top: 'center',
            feature : {
                mark : {show: true},
                dataView : {show: true, readOnly: false},
                restore : {show: true},
                saveAsImage : {show: true}
            }
        },
    };

    $.ajax({
        url:'${pageContext.request.contextPath}/User/showSexProportion',
        type:'get',
        dataType:'JSON',
        success:function (data) {

            myChart.setOption(option)
            myChart.setOption({
                series: [{
                    name: '销量',
                    type: 'bar',
                    data: data.list
                }]
            }),
           myLine.setOption(option1);
            myLine.setOption({
                series: [{
                    name: '人数',
                    type: 'line',
                    data: data.elist
                }]
            }),

            myChina.setOption(option2)
            myChina.setOption({
                series : [
                    {
                        name: '用户人数',
                        type: 'map',
                        mapType: 'china',
                        roam: false,
                        label: {
                            normal: {
                                show: false
                            },
                            emphasis: {
                                show: true
                            }
                        },
                        data:data.flist,
                    }
                ]
            })

        }
    })
    /*$.ajax({
        url:'/User/everyWeekCount',
        type:'get',
        dataType:'JSON',
        success:function (data) {

        }
    })*/
    // 1.基于准备好的dom，初始化echarts实例
    var Hello = echarts.init(document.getElementById('hello'));

    // 2.指定图表的配置项和数据


    // 3.使用刚指定的配置项和数据显示图表。


    var goEasy = new GoEasy({
        appkey:"BC-bc0efc3ab30840fcbdc87e9222df0107"
    });
    goEasy.subscribe({
        channel:"my_channel",
        onMessage:function (message) {
            var count=JSON.parse(message.content);

            var option = {
                title: {
                    text: '用户男女比例'
                },
                tooltip: {},
                legend: {
                    data:['人数']
                },
                xAxis: {
                    data: ["男","女"]
                },
                yAxis: {},
                series: [{
                    name: '人数',
                    type: 'line',
                    data: count,
                }]
            };
            Hello.setOption(option)
        }
    });



</script>
</body>
</html>